define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var storeId = 0;
    var Controller = {
        index: function () {
            storeId = $('#storeId').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/invite_statistics/index' + location.search + '&sid='+storeId,
                    // add_url: 'store/invite_statistics/add',
                    // edit_url: 'store/invite_statistics/edit',
                    // del_url: 'store/invite_statistics/del',
                    // multi_url: 'store/invite_statistics/multi',
                    // import_url: 'store/invite_statistics/import',
                    table: 'store_invite_statistics',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible:false},
                        {field: 'merchant_id', title: __('Merchant_id'),visible:false},
                        {field: 'merchant.company_name', title: __('Merchant.company_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'store_id', title: __('Store_id'),visible:false},
                        {field: 'store.store_name', title: __('Store.store_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'time_type', title: __('Time_type'), searchList: {"1":__('Time_type 1'),"2":__('Time_type 2'),"3":__('Time_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'year', title: __('Year')},
                        {field: 'month', title: __('Month')},
                        {field: 'day', title: __('Day')},
                        {field: 'number', title: __('Number')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
